<template>
  <div class="history-container">
    <div class="page-header">
      <h1>京剧发展历史</h1>
      <p>从清代到现代的京剧艺术发展历程</p>
    </div>

    <div class="timeline-container">
      <!-- 时间线导航 -->
      <div class="timeline-nav">
        <ul>
          <li v-for="(period, index) in historyPeriods" :key="index">
            <a :href="'#period-' + index" :class="{ active: activePeriod === index }" @click="setActivePeriod(index)">
              {{ period.year }}
            </a>
          </li>
        </ul>
      </div>

      <!-- 时间线内容区 -->
      <div class="timeline-content">
        <div v-for="(period, index) in historyPeriods" :key="index" :id="'period-' + index" class="period-section">
          <div class="period-header">
            <span class="period-year">{{ period.year }}</span>
            <h2>{{ period.title }}</h2>
          </div>
          <div class="period-content">
            <div class="period-image">
              <img :src="period.image" :alt="period.title">
            </div>
            <div class="period-text">
              <p v-for="(paragraph, pIndex) in period.description" :key="pIndex">{{ paragraph }}</p>
              <div class="period-characters" v-if="period.characters && period.characters.length">
                <h3>代表人物</h3>
                <div class="characters-list">
                  <div v-for="(character, cIndex) in period.characters" :key="cIndex" class="character-item">
                    <div class="character-avatar">
                      <img :src="character.avatar" :alt="character.name">
                    </div>
                    <div class="character-info">
                      <h4>{{ character.name }}</h4>
                      <p>{{ character.description }}</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="related-content">
      <h2>相关内容</h2>
      <div class="related-links">
        <router-link to="/artists" class="related-link">
          <span class="link-icon">👨‍🎤</span>
          <span class="link-text">名家大师</span>
        </router-link>
        <router-link to="/classics" class="related-link">
          <span class="link-icon">🎭</span>
          <span class="link-text">经典剧目</span>
        </router-link>
        <router-link to="/schools" class="related-link">
          <span class="link-icon">🏫</span>
          <span class="link-text">流派介绍</span>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HistoryVue',
  data() {
    return {
      activePeriod: 0,
      historyPeriods: [
        {
          year: '1790-1840年',
          title: '京剧起源与初步形成',
          image: require('@/assets/history/opera_source.jpg'),
          description: [
            '1790年，四大徽班进京，为乾隆八十大寿献艺，由此奠定了京剧形成的基础。徽班带来的昆曲、高腔、二黄等艺术形式，与北京地方戏曲相结合，逐渐形成了京剧的雏形。',
            '这一时期，安徽、湖北等地的戏班纷纷进京，带来了不同的地方戏曲风格。在不断的交流和融合中，京剧的曲调、表演和剧目逐渐丰富起来。'
          ],
          characters: [
            {
              name: '程长庚',
              avatar: require('@/assets/history/opera_ccg.jpg'),
              description: '被誉为京剧艺术的开山祖师之一，擅长老生行当，对京剧表演程式有重要贡献。'
            }
          ]
        },
        {
          year: '1840-1910年',
          title: '京剧的繁荣与定型',
          image: require('@/assets/history/sanqinban.jpg'),
          description: [
            '这一时期是京剧成熟与繁荣的重要阶段。1840年，三庆班的成立，标志着京剧作为一个独立剧种的正式形成。三庆班、四喜班、和春班等著名戏班的兴起，促进了京剧的迅速发展。',
            '同时，京剧的表演体系、行当分类、音乐体系等逐渐定型。传统剧目的整理与创新，使京剧剧目数量大幅增加，艺术表现力显著提高。'
          ],
          characters: [
            {
              name: '谭鑫培',
              avatar: require('@/assets/history/opera_txp.jpg'),
              description: '京剧老生行当的代表人物，为"谭派"艺术的创始人，精通武戏和文戏。'
            },
            {
              name: '杨小楼',
              avatar: require('@/assets/history/opera_yxl.jpg'),
              description: '著名武生演员，表演刚健有力，在武打和翻跟头等技艺方面造诣深厚。'
            }
          ]
        },
        {
          year: '1910-1949年',
          title: '京剧的创新与流派形成',
          image: require('@/assets/history/sidamingjue.png'),
          description: [
            '20世纪初至中华人民共和国成立前，是京剧艺术百花齐放的时期。梅兰芳、程砚秋、尚小云和荀慧生"四大名旦"的崛起，极大地丰富了京剧旦角的表演艺术。',
            '这一时期，京剧各大流派纷纷形成，如梅派、余派、马派、谭派、荀派等。不同流派各具特色，共同促进了京剧艺术的多元化发展。',
            '同时，京剧开始走向国际舞台，梅兰芳先生的出国演出，让京剧艺术在世界范围内获得了赞誉。'
          ],
          characters: [
            {
              name: '梅兰芳',
              avatar: require('@/assets/history/opera_mlf.jpg'),
              description: '京剧旦角表演艺术的集大成者，"梅派"艺术创始人，对京剧艺术的发展和传播有卓越贡献。'
            },
            {
              name: '程砚秋',
              avatar: require('@/assets/history/opera_cyq.jpg'),
              description: '"程派"艺术创始人，以细腻优美的表演风格著称，对青衣表演艺术有重要贡献。'
            }
          ]
        },
        {
          year: '1950-1980年',
          title: '京剧的现代化改革',
          image: require('@/assets/history/newchina.jpg'),
          description: [
            '中华人民共和国成立后，京剧艺术迎来了新的发展机遇。国家对京剧艺术的扶持力度加大，建立了专业的京剧院团和教育机构。',
            '这一时期，京剧在保留传统剧目的同时，创作了一批新编历史剧和现代戏，丰富了京剧的表现题材和内容。现代戏的创作与演出成为这一时期的重要特点。',
            '同时，京剧表演、音乐、舞台美术等方面也进行了一系列创新尝试，使京剧艺术焕发出新的活力。'
          ],
          characters: [
            {
              name: '张君秋',
              avatar: require('@/assets/history/opera_zjq.jpg'),
              description: '著名旦角表演艺术家，"张派"艺术创始人，在继承传统的基础上有所创新。'
            },
            {
              name: '李少春',
              avatar: require('@/assets/history/opera_lsc.jpg'),
              description: '著名老生表演艺术家，擅长传统剧目和现代戏的表演，表演风格独特。'
            }
          ]
        },
        {
          year: '1980年至今',
          title: '京剧的传承与创新',
          image: require('@/assets/history/opernow.png'),
          description: [
            '改革开放以来，京剧艺术进入了一个传承与创新并举的新时期。国家实施了一系列保护与传承非物质文化遗产的政策，京剧作为国家级非物质文化遗产得到了重点保护。',
            '同时，京剧艺术家积极探索京剧的现代表达方式，创作了一批既有传统韵味又具时代特色的新剧目。京剧与现代科技、现代艺术形式的结合，拓展了京剧的表现空间。',
            '此外，京剧"走出去"步伐加快，通过国际文化交流活动，京剧艺术在全球范围内的影响力不断扩大。年轻一代京剧艺术家的成长，为京剧艺术注入了新的活力。'
          ],
          characters: [
            {
              name: '于魁智',
              avatar: require('@/assets/history/opera_ykz.jpg'),
              description: '当代著名老生表演艺术家，在继承传统的基础上有所创新，培养了众多京剧人才。'
            },
            {
              name: '李胜素',
              avatar: require('@/assets/history/opera_lss.jpg'),
              description: '当代著名旦角表演艺术家，梅派艺术传人，表演风格大气典雅。'
            }
          ]
        }
      ]
    }
  },
  mounted() {
    document.title = '京剧苑 - 京剧发展历史'
    window.scrollTo(0, 0);
    this.observeTimelineSections()
    this.scrollToHash()
  },
  methods: {
    setActivePeriod(index) {
      this.activePeriod = index
    },
    // 监听滚动，高亮当前可见的时间段
    observeTimelineSections() {
      if (typeof IntersectionObserver !== 'undefined') {
        const observer = new IntersectionObserver((entries) => {
          entries.forEach(entry => {
            if (entry.isIntersecting) {
              const id = entry.target.id
              if (id && id.startsWith('period-')) {
                const index = parseInt(id.split('-')[1])
                this.activePeriod = index
              }
            }
          })
        }, { threshold: 0.5 })

        this.historyPeriods.forEach((_, index) => {
          const element = document.getElementById(`period-${index}`)
          if (element) observer.observe(element)
        })
      }
    },
    // 如果URL中有锚点，自动滚动到相应位置
    scrollToHash() {
      if (window.location.hash) {
        const hash = window.location.hash.substring(1)
        const element = document.getElementById(hash)
        if (element) {
          element.scrollIntoView({ behavior: 'smooth' })
          // 从hash中提取索引
          if (hash.startsWith('period-')) {
            const index = parseInt(hash.split('-')[1])
            if (!isNaN(index)) this.activePeriod = index
          }
        }
      }
    }
  }
}
</script>

<style scoped>
.history-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  text-align: center;
  margin-bottom: 3rem;
}

.page-header h1 {
  font-size: 2.5rem;
  color: #8B0000;
  margin-bottom: 0.5rem;
  font-family: 'STZhongsong', serif;
}

.page-header p {
  font-size: 1.2rem;
  color: #666;
}

/* 时间线容器 */
.timeline-container {
  display: flex;
  margin-bottom: 4rem;
}

/* 时间线导航 */
.timeline-nav {
  position: sticky;
  top: 2rem;
  align-self: flex-start;
  width: 150px;
  min-width: 150px;
  margin-right: 2rem;
  border-right: 1px solid #ddd;
  padding-right: 1rem;
  height: calc(100vh - 4rem);
  overflow-y: auto;
}

.timeline-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline-nav ul li {
  margin-bottom: 1rem;
}

.timeline-nav ul li a {
  display: block;
  padding: 0.5rem;
  text-decoration: none;
  color: #333;
  border-radius: 4px;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
}

.timeline-nav ul li a:hover {
  background: #f5f5f5;
  border-left-color: #ccc;
}

.timeline-nav ul li a.active {
  color: #8B0000;
  font-weight: bold;
  border-left-color: #8B0000;
  background: rgba(139, 0, 0, 0.05);
}

/* 时间线内容区 */
.timeline-content {
  flex: 1;
}

.period-section {
  margin-bottom: 4rem;
  padding-top: 1rem;
}

.period-header {
  margin-bottom: 2rem;
  position: relative;
}

.period-year {
  display: inline-block;
  padding: 0.25rem 1rem;
  background: #8B0000;
  color: #FFD700;
  border-radius: 20px;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.period-header h2 {
  font-size: 1.8rem;
  color: #8B0000;
  margin: 0.5rem 0;
  font-family: 'STZhongsong', serif;
}

.period-content {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.period-image {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.period-image img {
  width: 100%;
  height: 400px;
  /* object-fit: cover; */
  background-size: 100% 100%;
  display: block;
}

.period-text p {
  margin-bottom: 1rem;
  line-height: 1.6;
  text-align: justify;
}

/* 代表人物部分 */
.period-characters {
  margin-top: 2rem;
}

.period-characters h3 {
  color: #8B0000;
  margin-bottom: 1rem;
  font-family: 'STZhongsong', serif;
}

.characters-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.character-item {
  display: flex;
  background: #f9f9f9;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.character-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

.character-avatar {
  width: 100px;
  min-width: 100px;
}

.character-avatar img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}

.character-info {
  padding: 1rem;
}

.character-info h4 {
  margin: 0 0 0.5rem 0;
  color: #8B0000;
  font-family: 'STZhongsong', serif;
}

.character-info p {
  margin: 0;
  font-size: 0.9rem;
  color: #666;
}

/* 相关内容区域 */
.related-content {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid #eee;
}

.related-content h2 {
  text-align: center;
  color: #8B0000;
  margin-bottom: 2rem;
  font-family: 'STZhongsong', serif;
}

.related-links {
  display: flex;
  justify-content: center;
  gap: 2rem;
}

.related-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: #333;
  transition: transform 0.3s ease;
}

.related-link:hover {
  transform: translateY(-5px);
}

.link-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.link-text {
  font-weight: bold;
  color: #8B0000;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .timeline-container {
    flex-direction: column;
  }

  .timeline-nav {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #ddd;
    margin-right: 0;
    margin-bottom: 2rem;
    padding-right: 0;
    padding-bottom: 1rem;
  }

  .timeline-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .timeline-nav ul li {
    margin-bottom: 0;
  }

  .period-content {
    flex-direction: column;
  }

  .period-image, .period-text {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .history-container {
    padding: 1rem;
  }

  .page-header h1 {
    font-size: 2rem;
  }

  .characters-list {
    grid-template-columns: 1fr;
  }

  .related-links {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
  }
}
</style> 